<!--
 * @author: Victor
 * @Date: 2021-11-27 16:32:40
 * @LastEditTime: 2021-11-27 20:25:56
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="file" name="" id="myfile" />
    <img src="" alt="" id="img" />
    <script>
      myfile.onchange = function () {
        var file = this.files[0];
        var url = URL.createObjectURL(file);
        console.log(url, typeof url, file.slice(0, 1));
        // img.src = url;
        var fr = new FileReader();
        fr.readAsDataURL(file);
        fr.onload = function (e) {
          console.log(e, fr);
          img.src = fr.result;
        };
      };
    </script>
  </body>
</html>
